package com.yang.listener;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.sun.source.doctree.UnknownBlockTagTree;
import com.yang.CitizensNPC;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.util.EulerAngle;

import java.lang.reflect.Field;
import java.util.Base64;
import java.util.UUID;

public class ListenerNPC implements Listener {

    private static CitizensNPC citizensNPC;

    public ListenerNPC(CitizensNPC citizensNPC) {
        this.citizensNPC = citizensNPC;
        createNPC();
    }

    private void createNPC() {
        // 循环yml
        ConfigurationSection npc = citizensNPC.getConfig().getConfigurationSection("npc");
        for (String key : npc.getKeys(false)) {
            ConfigurationSection npcKey = npc.getConfigurationSection(key);
            String name = npcKey.getString("name");
            String command = npcKey.getString("command");
            String worldName = npcKey.getString("world");
            double x = npcKey.getDouble("x");
            double y = npcKey.getDouble("y");
            double z = npcKey.getDouble("z");
            String skin = npcKey.getString("skin");
            // 开始生成
            World world = Bukkit.getWorld(worldName);
            if (world != null) {
                Location location = new Location(world, x, y, z);
//                createSingleNPC(name, location, command, skin);
//                spawnNPC(location,skin);
                create1NPC();
            } else {
                Bukkit.getLogger().warning("World '" + worldName + "' not found for NPC creation.");
            }
        }
    }

    public void create1NPC() {
        Location location = new Location(Bukkit.getWorlds().get(0), 0, 100, 0); // 设置NPC的位置
        ArmorStand steve = location.getWorld().spawn(location, ArmorStand.class);
        steve.setCustomName("Steve");
        steve.setCustomNameVisible(true);
        steve.setGravity(false); // 不受重力影响
        steve.setVisible(false); // 不可见
    }
}